﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Dapper;
using Entity;
using IDAL;
namespace DAL
{
    public class TestDAL:ITestDAL
    {
        private static readonly  string connectStr = System.Configuration.ConfigurationManager.ConnectionStrings["testdb"].ConnectionString;
        private IDbConnection GetOpenConnection()
        {

            IDbConnection connection = new SqlConnection(connectStr);
            connection.Open();
            return connection;
        }

        public void DelTest(int id)
        {
            using (var connection = GetOpenConnection())
            {
                connection.Execute("delete from test where id=@id", new { id = id });

            }
        }

        public IList<Test> GetTestList()
        {
            using (var connection = GetOpenConnection())
            {
               return connection.GetList<Test>().ToList();

            }
        }

        public IList<V_ExamRequestQuery> GetExamRequestList()
        {
            using (var connection = GetOpenConnection())
            {
                return connection.GetList<V_ExamRequestQuery>().ToList();

            }
        }
        public  V_ExamRequestQuery  GetExamRequesByExamID(int examRequestID)
        {
            using (var connection = GetOpenConnection())
            {
                return connection.Get<V_ExamRequestQuery>(examRequestID);

            }
        }

        public IList<UploadTask> GetUploasTaskList(int count)
        {
            using (var connection = GetOpenConnection())
            {
                return connection.GetList<UploadTask>().ToList().OrderBy(t=>t.ExamRequestID).Skip(0).Take(count).ToList();
            }
        }
    }
}
